/*
 Copyright (c) 2014 ABB Group
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
    K. Eric Harper (ABB Corporate Research)
*/

using System;
using System.Windows.Forms;
using EAFacade;
using EAFacade.Model;

namespace DecisionArchitect.Model
{
    public class ScenarioElement
    {
        // Labels for force scenarios
        public static string[] ID = new string[]
        {
            "Source",
            "Stimulus",
            "Artifact",
            "Environment",
            "Response",
            "ResponseMeasure",
            "Result",
        };
        public static string[] Label = new string[]
        {
            "Source",
            "Stimulus",
            "Artifact",
            "Environment",
            "Response",
            "Response Measure",
            "Result",
        };

        private string _value;

        public string ElementType { get; set; }
        public int ColumnOffset { get; set; }
        public string ClassifiedByGUID { get; set; }
        public string ConcernGUID { get; set; }
        public string ForceGUID { get; set; }

        public string Value
        {
            get { return _value; }
            set
            {
                _value = value;
                if (_value.Length <= 255) return;
                IEARepository repository = EAMain.Repository;
                IEAElement force = repository.GetElementByGUID(ForceGUID);
                IEAElement concern = repository.GetElementByGUID(ConcernGUID);
                MessageBox.Show(
                    String.Format(
                        "The length of description '{0}' for element '{1}' that belongs to force '{2}' classified by '{3}' is too large. It must be less than 256 characters.",
                        _value, ElementType, force.Name, concern.Name));
                _value = "";
            }
        }

        /// <summary>
        /// </summary>
        /// <returns></returns>
        public static string ConstructClassifiedByTaggedValue(string elementType)
        {
            return String.Format("DV.Scenario:{0}", elementType);
        }

        public static string GetElementTypeFromTaggedValue(string value)
        {
            return value.Split(':')[1];
        }

        public static int GetColumnOffset(string value)
        {
            int offset = -1;
            string elementType = GetElementTypeFromTaggedValue(value);
            for( int i = 0; i < ID.Length; i++)
            {
                if (ID[i] == elementType)
                {
                    offset = i;
                    break;
                }
            }
            return offset;
        }

        /// <summary>
        ///     Checks if the tagged value of the
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsScenarioTaggedValue(string value)
        {
            return value.Split(':')[0].Equals("DV.Scenario");
        }
    }
}